<!--
 * @Author: zqx me_zqx@163.com
 * @Date: 2025-01-07 18:38:22
 * @LastEditors: zqx me_zqx@163.com
 * @LastEditTime: 2025-01-16 16:21:47
 * @FilePath: /meeting-minutes-h5/src/components/ConferenceMinutes/Counselling/CounsellingTaskCompletion.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="flex flex-col w-full h-full p-4">
    <TopCard
      :des="`完成任务数：${cp_completedSubTasks.length} / 总任务数：${cp_totalSubTasks.length}`"
      :title="'任务达成率'"
      :source="cp_completionRate"
      :unit="'%'"
      :dimension="evaluationDimension"
      :needStudy="false"
      :suggestions="improvementSuggestions"
    />
    <div class="mt-5">
      <div>
        <TaskCompletionCard v-for="(item, index) in cp_tasks" :item="item" :key="index" />
      </div>
    </div>
  </div>
</template>

<script>
import TopCard from "./component/topCard.vue";
import TaskCompletionCard from "./component/taskCompletionCard.vue";
import { useMinutesStore } from "@/store";
import { mapState } from "pinia";

export default {
  name: "CounsellingTaskCompletion",
  components: {
    TopCard,
    TaskCompletionCard,
  },
  computed: {
    ...mapState(useMinutesStore, {
      salesCounsellingReports: "salesCounsellingReports",
      enableImprovement: "enableImprovement",
    }),
    taskCompletionReport() {
      let arr = this.salesCounsellingReports.filter((v) => v.systemId == 206) || [];
      if (arr.length == 0) {
        return {};
      }
      let report = arr[0].report;
      return report;
    },
    // 整体评价
    evaluationDimension() {
      return this.taskCompletionReport.response?.overallEvaluation || "";
    },

    // 改进建议
    improvementSuggestions() {
      return this.taskCompletionReport.response?.improvementSuggestions || [];
    },

    // 任务数组
    cp_tasks() {
      return this.taskCompletionReport.tasks || [];
    },
    // 总子任务
    cp_totalSubTasks() {
      let tasks = this.cp_tasks || [];
      let subTasks = [];
      tasks.forEach((task) => {
        subTasks = subTasks.concat(task.content.evaluationResults.subTasks || []);
      });
      return subTasks;
    },

    // 总完成子任务数
    cp_completedSubTasks() {
      let array = this.cp_totalSubTasks.filter((v) => v.status === "complete") || [];
      return array;
    },

    // 完成率
    cp_completionRate() {
      return (
        (
          (this.cp_completedSubTasks.length / this.cp_totalSubTasks.length) * 100 || 0
        ).toFixed(0) || 0
      );
    },
  },
};
</script>

<style lang="less" scoped></style>
